package com.tree.backend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tree.backend.entity.pojo.PartyProductionLink;
import com.tree.backend.entity.vo.PartyProductionLinkData;
import com.tree.backend.entity.vo.ProductionTrendData;
import com.tree.backend.entity.vo.QualityAnalysisData;
import com.tree.backend.mapper.PartyProductionLinkMapper;
import com.tree.backend.service.IPartyProductionLinkService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 党建与生产关联表，记录党建活动对生产经营的具体贡献和影响 服务实现类
 * </p>
 *
 * @author tree
 * @since 2025-10-15
 */
@Service
@RequiredArgsConstructor
public class PartyProductionLinkServiceImpl extends ServiceImpl<PartyProductionLinkMapper, PartyProductionLink> implements IPartyProductionLinkService {

    private final PartyProductionLinkMapper partyProductionLinkMapper;

    @Override
    public HashMap<String, ArrayList> qualityAnalysis() {
        List<QualityAnalysisData> qualityAnalysisData = partyProductionLinkMapper.qualityAnalysis();
        HashMap<String, ArrayList> map = new HashMap<>();
        map.put("organizations", new ArrayList<String>());
        map.put("qualityRates", new ArrayList<Double>());
        map.put("qualityImprovements", new ArrayList<Double>());
        for (QualityAnalysisData data : qualityAnalysisData) {
            map.get("organizations").add(data.getOrganizations());
            map.get("qualityRates").add(data.getQualityRates());
            map.get("qualityImprovements").add(data.getQualityImprovements());
        }
        return map;
    }

    @Override
    public HashMap<String, ArrayList> efficiencyTrend() {
        List<ProductionTrendData> productionTrendData = partyProductionLinkMapper.efficiencyTrend();
        HashMap<String, ArrayList> map = new HashMap<>();
        map.put("months", new ArrayList<String>());
        map.put("productionValues", new ArrayList<Double>());
        for (ProductionTrendData data : productionTrendData) {
            map.get("months").add(data.getMonth());
            map.get("productionValues").add(data.getProductionValue());
        }
        return map;
    }

    @Override
    public HashMap<String, ArrayList> link() {
        List<PartyProductionLinkData> partyProductionLinkDataList = partyProductionLinkMapper.link();
        HashMap<String, ArrayList> map = new HashMap<>();
        map.put("links",new ArrayList<>(partyProductionLinkDataList));
        return map;
    }
}
